package cn.iocoder.yudao.module.exam.utils;

import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.exam.controller.admin.questionoption.vo.QuestionOptionSaveReqVO;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.commons.compress.utils.Lists;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@MappedTypes(List.class)
@MappedJdbcTypes(JdbcType.VARCHAR)
public class QuestionOptionListTypeHandler extends AbstractJsonTypeHandler<List<QuestionOptionSaveReqVO>> {

    @Override
    protected List<QuestionOptionSaveReqVO> parse(String json) {
        return JsonUtils.parseArray(json,QuestionOptionSaveReqVO.class);
    }

    @Override
    protected String toJson(List<QuestionOptionSaveReqVO> obj) {
        obj = obj == null? Lists.newArrayList():obj;
        return JsonUtils.toJsonString(obj);
    }
}